//
//  JBaseCollectionViewCell.m
//  HeadIndustry
//
//  Created by jun on 2017/8/24.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JBaseCollectionViewCell.h"
#import <YYImage.h>
@implementation JBaseCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.opaque = NO;
        [self setUpBgView];
    }
    return self;
}

- (void)setUpBgView
{
    _imgLayer = [CALayer layer];
    _imgLayer.contents = (__bridge id _Nullable)([YYImage imageNamed:@""].CGImage);
    _imgLayer.top = 0;
    _imgLayer.left = 0;
    _imgLayer.size = CGSizeMake(self.width, self.height - 50);
    [self.layer addSublayer:_imgLayer];
    
    _titleLabel = [YYLabel new];
    _titleLabel.top = _imgLayer.bottom;
    _titleLabel.left = 0;
    _titleLabel.size = CGSizeMake(self.width, 30);
    _titleLabel.font = kFONT_TITLE(16);
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    
    _priceLabel = [YYLabel new];
    _priceLabel.top = _titleLabel.bottom;
    _priceLabel.left = 0;
    _priceLabel.size = CGSizeMake((self.width )/2.0 -  5, 20);
    _priceLabel.font = kFONT_TITLE(14);
    _priceLabel.textAlignment = NSTextAlignmentRight;
    _priceLabel.textColor = [UIColor redColor];
    _priceLabel.text = @"¥99元";
    [self addSubview:_priceLabel];
    
    _statueLabel = [YYLabel new];
    _statueLabel.top = _titleLabel.bottom;
    _statueLabel.left = _priceLabel.right + 5;
    _statueLabel.size = CGSizeMake((self.width )/2.0 - 5, 20);
    _statueLabel.font = kFONT_TITLE(14);
    _statueLabel.textAlignment = NSTextAlignmentLeft;
    _statueLabel.textColor = kRGBColor(200, 200, 200);
    _statueLabel.text = @"已售10件";
    [self addSubview:_statueLabel];
}

- (void)setProdeutModel:(JProductDetailModel *)prodeutModel
{
    _prodeutModel = prodeutModel;
    NSURL *imageURL = [NSURL URLWithString:prodeutModel.ImgUrl];
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];

    dispatch_async(dispatch_get_main_queue(), ^{
        _imgLayer.contents = (__bridge id _Nullable)([YYImage imageWithData:imageData].CGImage);
        _imgLayer.cornerRadius = 8;
        _imgLayer.masksToBounds = YES;
        _priceLabel.text = prodeutModel.PriceText;
        _titleLabel.text = prodeutModel.Name;
        _statueLabel.text = [NSString stringWithFormat:@"已售%ld件",(long)prodeutModel.m_SalesCount];
    });
    
}

@end
